{% set pypi_name = 'tempest' %}
{% set upstream_version = upstream_version('25.0.1') %}
{% set rpm_release = '1' %}
{% set source = url_pypi() %}

Name:           {{ py2name() }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Epoch:          {{ epoch('tempest') }}
Summary:        The OpenStack Integration Test Suite (Tempest)
License:        {{ license('Apache-2.0') }}
Group:          Development/Languages/Python
URL:            https://docs.openstack.org/tempest
Source0:        {{ source }}
Source1:        openstack-tempest.tmpfiles
BuildRequires:  openstack-macros
BuildRequires:  {{ py3('PrettyTable') }}
BuildRequires:  {{ py3('PyYAML') }}
BuildRequires:  {{ py3('cliff') }}
BuildRequires:  {{ py3('debtcollector') }}
BuildRequires:  {{ py3('fixtures') }}
BuildRequires:  {{ py3('jsonschema') }}
BuildRequires:  {{ py3('netaddr') }}
BuildRequires:  {{ py3('oslo.concurrency') }}
BuildRequires:  {{ py3('oslo.config') }}
BuildRequires:  {{ py3('oslo.log') }}
BuildRequires:  {{ py3('oslo.serialization') }}
BuildRequires:  {{ py3('oslo.utils') }}
BuildRequires:  {{ py3('paramiko') }}
BuildRequires:  {{ py3('python-subunit') }}
BuildRequires:  {{ py3('six') }}
BuildRequires:  {{ py3('stestr') }}
BuildRequires:  {{ py3('stevedore') }}
BuildRequires:  {{ py3('testtools') }}
BuildRequires:  {{ py3('unittest2') }}
BuildRequires:  {{ py3('urllib3') }}
Requires:       python3-{{ pypi_name }} = %{epoch}:%{version}-%{release}
BuildArch:      noarch
%if 0%{?suse_version}
# to be compatible with older tempest packages
Provides:       openstack-tempest-test = %{epoch}:%{version}-%{release}
Obsoletes:      openstack-tempest-test < %{epoch}:%{version}-%{release}
%endif

%description
Tempest is a set of integration tests to be run against a live OpenStack
cluster. Tempest has batteries of tests for OpenStack API validation,
Scenarios, and other specific tests useful in validating an OpenStack
deployment.

%package -n python3-{{ pypi_name }}
Summary:        Documentation for the OpenStack Integration Test Suite
Group:          Development/Languages/Python
Requires:       {{ py3('PrettyTable') }}
Requires:       {{ py3('PyYAML') }}
Requires:       {{ py3('cliff') }}
Requires:       {{ py3('debtcollector') }}
Requires:       {{ py3('fixtures') }}
Requires:       {{ py3('jsonschema') }}
Requires:       {{ py3('netaddr') }}
Requires:       {{ py3('oslo.concurrency') }}
Requires:       {{ py3('oslo.config') }}
Requires:       {{ py3('oslo.log') }}
Requires:       {{ py3('oslo.serialization') }}
Requires:       {{ py3('oslo.utils') }}
Requires:       {{ py3('paramiko') }}
Requires:       {{ py3('python-subunit') }}
Requires:       {{ py3('six') }}
Requires:       {{ py3('stestr') }}
Requires:       {{ py3('stevedore') }}
Requires:       {{ py3('testtools') }}
Requires:       {{ py3('unittest2') }}
Requires:       {{ py3('urllib3') }}

%description -n python3-{{ pypi_name }}
Tempest is a set of integration tests to be run against a live OpenStack
cluster. Tempest has batteries of tests for OpenStack API validation,
Scenarios, and other specific tests useful in validating an OpenStack
deployment.

This package contains the python module.

%package doc
Summary:        Documentation for the OpenStack Integration Test Suite
BuildRequires:  {{ py3('Sphinx') }}
BuildRequires:  {{ py3('openstackdocstheme') }}
BuildRequires:  {{ py3('sphinxcontrib-svg2pdfconverter') }}

%description doc
Tempest is a set of integration tests to be run against a live OpenStack
cluster. Tempest has batteries of tests for OpenStack API validation,
Scenarios, and other specific tests useful in validating an OpenStack
deployment.

This package contains the documentation.

%prep
%autosetup -p1 -n {{ pypi_name }}-{{ upstream_version }}
%py_req_cleanup

%build
%{py3_build}

# generate html docs
PBR_VERSION={{ upstream_version }} %sphinx_build -b html doc/source doc/build/html
# remove the sphinx-build leftovers
rm -rf doc/build/html/.{doctrees,buildinfo}


%install
%{py3_install}

# NOTE(toabctl): config files are installed into usr/etc/
install -d -m 755 %{buildroot}%{_sysconfdir}/tempest
mv %{buildroot}/%{_prefix}/%{_sysconfdir}/{{ pypi_name }}/accounts.yaml.sample %{buildroot}/%{_sysconfdir}/{{ pypi_name }}/accounts.yaml
mv %{buildroot}/%{_prefix}/%{_sysconfdir}/{{ pypi_name }}/logging.conf.sample %{buildroot}/%{_sysconfdir}/{{ pypi_name }}/logging.conf
mv %{buildroot}/%{_prefix}/%{_sysconfdir}/{{ pypi_name }}/whitelist.yaml %{buildroot}/%{_sysconfdir}/{{ pypi_name }}/whitelist.yaml

# install config
PYTHONPATH=. oslo-config-generator --config-file %{_builddir}/{{ pypi_name }}-{{ upstream_version }}/tempest/cmd/config-generator.tempest.conf --output-file %{buildroot}%{_sysconfdir}/tempest/tempest.conf

# install tmpfiles
install -D -m 644 %{SOURCE1} %{buildroot}/%_tmpfilesdir/%{name}.conf

%if 0%{?suse_version}
# to be compatible with older tempest packages
%openstack_test_package_install {{ pypi_name }}
cp -av .stestr.conf %{buildroot}/%{_localstatedir}/lib/%{name}-test/
%endif

%post
%tmpfiles_create %{_tmpfilesdir}/%{name}.conf

%files
%license LICENSE
%doc README.rst ChangeLog
%_tmpfilesdir/%{name}.conf
%{_bindir}/tempest

%{_bindir}/skip-tracker
%{_bindir}/check-uuid
%{_bindir}/subunit-describe-calls
%dir %{_sysconfdir}/tempest
%config(noreplace) %{_sysconfdir}/tempest/tempest.conf
%config(noreplace) %{_sysconfdir}/tempest/logging.conf
%config(noreplace) %{_sysconfdir}/tempest/accounts.yaml
%config(noreplace) %{_sysconfdir}/tempest/whitelist.yaml
%if 0%{?suse_version}
%{_localstatedir}/lib/openstack-tempest-test
%endif

%files -n python3-{{ pypi_name }}
%license LICENSE
%{python3_sitelib}/tempest
%{python3_sitelib}/*.egg-info

%files doc
%license LICENSE
%doc doc/build/html

%changelog
